package com.ruoyi.project.system.node.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.node.domain.CtcpNode;
import com.ruoyi.project.system.node.service.ICtcpNodeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * CTCP计算节点Controller
 * 
 * @author huzhenyuan
 * @date 2021-07-15
 */
@Controller
@RequestMapping("/system/node")
public class CtcpNodeController extends BaseController
{
    private String prefix = "system/node";

    @Autowired
    private ICtcpNodeService ctcpNodeService;

    @RequiresPermissions("system:node:view")
    @GetMapping()
    public String node()
    {
        return prefix + "/node";
    }

    /**
     * 查询CTCP计算节点列表
     */
    @RequiresPermissions("system:node:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CtcpNode ctcpNode)
    {
        startPage();
        List<CtcpNode> list = ctcpNodeService.selectCtcpNodeList(ctcpNode);
        return getDataTable(list);
    }

    /**
     * 导出CTCP计算节点列表
     */
    @RequiresPermissions("system:node:export")
    @Log(title = "CTCP计算节点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CtcpNode ctcpNode)
    {
        List<CtcpNode> list = ctcpNodeService.selectCtcpNodeList(ctcpNode);
        ExcelUtil<CtcpNode> util = new ExcelUtil<CtcpNode>(CtcpNode.class);
        return util.exportExcel(list, "CTCP计算节点数据");
    }

    /**
     * 新增CTCP计算节点
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存CTCP计算节点
     */
    @RequiresPermissions("system:node:add")
    @Log(title = "CTCP计算节点", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CtcpNode ctcpNode)
    {
        return toAjax(ctcpNodeService.insertCtcpNode(ctcpNode));
    }

    /**
     * 修改CTCP计算节点
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CtcpNode ctcpNode = ctcpNodeService.selectCtcpNodeById(id);
        mmap.put("ctcpNode", ctcpNode);
        return prefix + "/edit";
    }

    /**
     * 修改保存CTCP计算节点
     */
    @RequiresPermissions("system:node:edit")
    @Log(title = "CTCP计算节点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CtcpNode ctcpNode)
    {
        return toAjax(ctcpNodeService.updateCtcpNode(ctcpNode));
    }

    /**
     * 删除CTCP计算节点
     */
    @RequiresPermissions("system:node:remove")
    @Log(title = "CTCP计算节点", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ctcpNodeService.deleteCtcpNodeByIds(ids));
    }
}
